<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/13 0013
 * Time: 上午 11:00
 */

namespace Home\Model;
use Think\Model;

class UsersModel extends Model{

    //根据useID调用微信获取成员信息的接口,并把信息存到users表
    public function setuser($access_token,$userid){
        $url = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token={$access_token}&userid={$userid}";
        $info = json_decode(https_request($url),true);
        //dump($info);exit;
        $this->add(array(
            'userid' => $userid,
            'name' => $info['name'],
            'avatar' => $info['avatar'],
            'mobile' => $info['mobile']
        ));
    }

    //取出人员的具体信息
    public function getusersinfo($userid){
        $info = $this->field('name,avatar,mobile')->where("userid='{$userid}'")->find();
        return $info;
    }


    //获取userid的名称
    public function get_username($userid){
        $info = $this->field('name')->where("userid='{$userid}'")->find();
        return $info['name'];
    }
}